<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: showreport.php 1126 2008-06-09 05:45:04Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 
  function showReport ($mid, &$joomleague) {
    global $mainframe, $overall_config;
    global $htmlHelper;
    
	  $match = new Match($joomleague->_db);
	  $match->load($mid);
	  $positions = $joomleague->getPositions();
      $show_roster=false;
	  foreach ($positions AS $key=>$pos) {
	   $sortedhome[$key] = $match->getRoster($match->matchpart1, $key);
	   $sortedaway[$key] = $match->getRoster($match->matchpart2, $key);
       if(count($sortedhome[$key]) > 0 || count($sortedaway[$key]) > 0) $show_roster=true;
	  }
	  $mainframe->setPageTitle(_JL_PAGE_TITLE_SHOW_REPORT);
//      $mainframe->appendPathWay(_JL_PAGE_TITLE_SHOW_REPORT);
      
    if ($joomleague->teams_as_referees)
    {
      $referee = new JL_Team($joomleague->_db);
    }
    else
    {  
      $referee = new Referee($joomleague->_db);    
    }
    $referee->load($match->referee_id);
    // commenting reference to an unexistent table...
//    $query = sprintf("SELECT * FROM #__joomleague_match_comments WHERE match_id = %s AND published", $match->match_id);
//    $joomleague->_db->setQuery($query);
//    $comments = $joomleague->_db->loadObjectList();
      
    // Vereinslogos abfragen
    $team1 = new JL_Team($joomleague->_db);
    $team1->load($match->matchpart1);
    
    $team2 = new JL_Team($joomleague->_db);
    $team2->load($match->matchpart2);
    
    $teams[] = $team1;
    $teams[] = $team2;
      
    # so, we have the match, get the images from clubs
    $query = sprintf("SELECT logo_big FROM #__joomleague_clubs clubs
                   LEFT JOIN #__joomleague_teams teams ON clubs.id = teams.club_id
                       WHERE teams.id = %s", $match->matchpart1);
    $joomleague->_db->setQuery($query);
    $matchpart1_pic = $joomleague->_db->loadResult();
    
    $query = sprintf("SELECT logo_big FROM #__joomleague_clubs clubs
                   LEFT JOIN #__joomleague_teams teams ON clubs.id = teams.club_id
                       WHERE teams.id = %s", $match->matchpart2);
    $joomleague->_db->setQuery($query);
    $matchpart2_pic = $joomleague->_db->loadResult();
    
    $matchpart_pics[] = (trim($matchpart1_pic) != "")? sprintf('<img src="%s/%s" alt="%s" title="%s"/>', _JOOMLA_JL_LIVE_SITE, $matchpart1_pic, $teams[0]->name, $teams[0]->name) : "&nbsp;";
    $matchpart_pics[] = (trim($matchpart2_pic) != "")? sprintf('<img src="%s/%s" alt="%s" title="%s"/>', _JOOMLA_JL_LIVE_SITE, $matchpart2_pic, $teams[1]->name, $teams[1]->name) : "&nbsp;";

    $round = new Round ($joomleague->_db);
    $round->load($match->round_id);

    require(getTemplateFile(JL_TEMPLATE_PATH, 'show_report.tpl.php'));
}

?>